﻿using System;
using System.Configuration;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using mojoPortal.Web.RS.SBM.AppCode.Lib;

namespace mojoPortal.Web.RS.SBM.Controls
{
    public partial class EstimateControl : RSBaseUserControl
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void SetControlEnabledState(bool bstate = false)
        {
            RSSBMCommonFunctions.SetControlsEnabledState(this, bstate);
        }
        protected void btnViewEstimateReport_Click(Object sender, EventArgs e)
        {
            int estimateid = 0;
            RSUserIdentity userIdentity = GetRSUserIdentity();
            estimateid = txtEstimateId.Text == "" ? 0 : Convert.ToInt32(txtEstimateId.Text);
            Response.Redirect("RSEstimateReport.aspx?estimateid=" + estimateid);
        }
        protected void btnEditEstimate_Click(Object sender, EventArgs e)
        {
            RSUserIdentity userIdentity = GetRSUserIdentity();
            if (userIdentity.RSCanWrite)
            {
                SetControlEnabledState(true);
                btnEditEstimate.Visible = false;
                btnSaveEstimate.Visible = true;
                btnRemoveEstimate.Visible = true;
                btnCancel.Visible = true;
            }
            else
                ucModalActionMessageControl.ShowModal("You Do Not Have Permission To Perform This Action!", "", false);
        }
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            var nameValues = HttpUtility.ParseQueryString(Request.QueryString.ToString());
            nameValues.Set("tabindex", "0");
            string url = Request.Url.AbsolutePath;
            string updatedQueryString = "?" + nameValues.ToString();
            Response.Redirect(url + updatedQueryString);
        }
        protected void btnReturn_Click(Object sender, EventArgs e)
        {
            string prevurl = string.Empty;
            int locationId = hfLocationId.Value == "" ? 0 : Convert.ToInt32(hfLocationId.Value);
            if (Session["PreviousURL"] != null)
                prevurl = Session["PreviousURL"].ToString();
            else
                prevurl = Request.UrlReferrer.ToString();
            if (prevurl.Contains("RSLocationHistory") || prevurl.Contains("RSEstimateDetail"))
                Response.Redirect("~/RS/SBM/RSLocationHistoryEstimates.aspx?locationid=" + locationId);
            else
                Response.Redirect(prevurl);
        }
        protected void btnSaveEstimate_Click(Object sender, EventArgs e)
        {
            RSUserIdentity userIdentity = GetRSUserIdentity();
            int CompanyId = userIdentity.RSCompanyId;

            int LocationId = hfLocationId.Value == "" ? 0 : Convert.ToInt32(hfLocationId.Value);
            int EstimateId = txtEstimateId.Text == "" ? 0 : Convert.ToInt32(txtEstimateId.Text);
            int ProjectId = hfProjectId.Value == "" ? 0 : Convert.ToInt32(hfProjectId.Value);

            int BillingContactId = ddlBillingContactId.SelectedValue == "" ? 0 : Convert.ToInt32(ddlBillingContactId.SelectedValue);
            string Term = txtTerm.Text.Trim();
            string PONumber = txtPONumber.Text.Trim();
            string AdditionalInstruction = txtAdditionalInstruction.Text.Trim();

            string WorkOrderName = txtWorkOrderName.Text.Trim();
            string StartDT = txtStartDate.Text + " " + txtStartTime.Text.Trim();
            string EndDT = txtEndDate.Text + " " + txtEndTime.Text.Trim();
            string Description = txtDescription.Text.Trim();
            string Response = txtResponse.Text.Trim();

            float LaborCost = txtLaborCost.Text == "" ? 0 : Convert.ToSingle(txtLaborCost.Text);
            int DiscountPercent = txtDiscountPercent.Text == "" ? 0 : Convert.ToInt32(txtDiscountPercent.Text);
            float DiscountAmount = txtDiscountAmount.Text == "" ? 0 : Convert.ToSingle(txtDiscountAmount.Text);

            int WorkOrderTypeID = Convert.ToInt32(ddlWorkOrderType.SelectedValue);
            int ScheduleTypeID = Convert.ToInt32(ddlScheduleType.SelectedValue);
            int StatusID = Convert.ToInt32(ddlEstimateStatus.SelectedValue);

            SqlCommand sqlCmd = new SqlCommand();

            SQLHelper.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@WorkOrderName", SqlDbType.NVarChar, 150, ParameterDirection.Input, WorkOrderName);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@Description", SqlDbType.NVarChar, -1, ParameterDirection.Input, Description);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@Response", SqlDbType.NVarChar, -1, ParameterDirection.Input, Response);
            
            if(StartDT.Trim().Length > 0)
                SQLHelper.AddParamToSQLCmd(sqlCmd, "@StartDT", SqlDbType.DateTime, 0, ParameterDirection.Input, Convert.ToDateTime(StartDT));
            if(EndDT.Trim().Length > 0)
                SQLHelper.AddParamToSQLCmd(sqlCmd, "@EndDT", SqlDbType.DateTime, 0, ParameterDirection.Input, Convert.ToDateTime(EndDT));

            SQLHelper.AddParamToSQLCmd(sqlCmd, "@LaborCost", SqlDbType.Money, 0, ParameterDirection.Input, LaborCost);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@DiscountPercent", SqlDbType.SmallInt, 0, ParameterDirection.Input, DiscountPercent);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@DiscountAmount", SqlDbType.Money, 0, ParameterDirection.Input, DiscountAmount);

            SQLHelper.AddParamToSQLCmd(sqlCmd, "@AdditionalInstructions", SqlDbType.NVarChar, 250, ParameterDirection.Input, AdditionalInstruction);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@Terms", SqlDbType.NVarChar, 250, ParameterDirection.Input, Term);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@PONumber", SqlDbType.NVarChar, 50, ParameterDirection.Input, PONumber);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@BillingContactId", SqlDbType.Int, 0, ParameterDirection.Input, BillingContactId);

            SQLHelper.AddParamToSQLCmd(sqlCmd, "@WorkOrderTypeID", SqlDbType.Int, 0, ParameterDirection.Input, WorkOrderTypeID);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@AppointmentTypeID", SqlDbType.Int, 0, ParameterDirection.Input, ScheduleTypeID);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@EstimateStatusId", SqlDbType.Int, 0, ParameterDirection.Input, StatusID);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@ProjectId", SqlDbType.Int, 0, ParameterDirection.Input, ProjectId);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@EstimateId", SqlDbType.Int, 0, ParameterDirection.Input, EstimateId);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@LocationId", SqlDbType.Int, 0, ParameterDirection.Input, LocationId);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@CompanyId", SqlDbType.Int, 0, ParameterDirection.Input, CompanyId);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@CurrentUser", SqlDbType.NVarChar, 25, ParameterDirection.Input, userIdentity.RSCurrentUser);
            if (ddlEstimateStatus.SelectedItem.Text.ToLower() == "accepted" || ddlEstimateStatus.SelectedItem.Text.ToLower() == "approved")
            {
                SQLHelper.AddParamToSQLCmd(sqlCmd, "@EstimateAcceptedDT", SqlDbType.DateTime, 0, ParameterDirection.Input, DateTime.Today);
            }

            SQLHelper.SetCommandType(sqlCmd, CommandType.StoredProcedure, "rs_uspSaveEstimate");
            SQLHelper.ExecuteScalarCmd(sqlCmd);

            int returnValue = Convert.ToInt32(sqlCmd.Parameters["@ReturnValue"].Value);
            ucModalActionMessageControl.ShowModal("Estimate Successfully Saved!", "RSEstimateDetail.aspx?locationid=" + LocationId + "&Estimateid=" + returnValue, true);
        }

        protected void btnRemoveEstimate_Click(Object sender, EventArgs e)
        {
            RSUserIdentity userIdentity = GetRSUserIdentity();
            if (userIdentity.RSCanWrite && userIdentity.RSCanDelete)
            {
                int CompanyId = userIdentity.RSCompanyId;
                int LocationId = hfLocationId.Value == "" ? 0 : Convert.ToInt32(hfLocationId.Value);
                int EstimateId = txtEstimateId.Text == "" ? 0 : Convert.ToInt32(txtEstimateId.Text);

                if (CompanyId > 0 && EstimateId > 0 && LocationId > 0)
                {
                    SqlCommand sqlCmd = new SqlCommand();
                    SQLHelper.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
                    SQLHelper.AddParamToSQLCmd(sqlCmd, "@companyid", SqlDbType.Int, 0, ParameterDirection.Input, CompanyId);
                    SQLHelper.AddParamToSQLCmd(sqlCmd, "@Estimateid", SqlDbType.Int, 0, ParameterDirection.Input, EstimateId);
                    SQLHelper.SetCommandType(sqlCmd, CommandType.StoredProcedure, "rs_uspDeleteEstimate");
                    SQLHelper.ExecuteScalarCmd(sqlCmd);
                    int returnValue = Convert.ToInt32(sqlCmd.Parameters["@ReturnValue"].Value);
                    ucModalActionMessageControl.ShowModal("Estimate and Associations Deleted Successfully!", "~/RS/SBM/RSLocationHistoryEstimates.aspx?locationid=" + LocationId, true);
                }
            }
            else
                ucModalActionMessageControl.ShowModal("You Do Not Have Permission To Perform This Action!", "", false);

        }

        public bool LoadEstimateDataByID(int companyid, int locationid, int Estimateid)
        {
            bool bHaveData = false;
            if (companyid > 0 && locationid > 0)
            {
                RSSBMDataLookupLoader.LoadTypeDDL(companyid, "WORKORDER_CAT", ddlWorkOrderType);
                RSSBMDataLookupLoader.LoadTypeDDL(companyid, "SCHEDULE_CAT", ddlScheduleType);
                RSSBMDataLookupLoader.LoadStatusDDL(companyid, "ESTIMATE_CAT", ddlEstimateStatus);
                hfLocationId.Value = locationid.ToString();
                LoadBillingContactByLocationID(companyid, locationid);

                if (Estimateid > 0)
                {
                    String strSQL = "SELECT EstimateId,WorkOrderName,Description,Response,StartDT,EndDT,WorkOrderTypeId,AppointmentTypeId,LaborCost,DiscountPercent,DiscountAmount,BillingContactId,EstimateStatusId,ProjectId,LocationId,CompanyId,AdditionalInstructions,PONumber,Terms,IsEstimateGenerated,IsRolledIntoWorkOrder FROM dbo.rs_tblEstimate WHERE EstimateID=@Estimateid AND CompanyId=@companyid";
                    SqlCommand myCommand;
                    SqlParameter param;
                    SqlConnection myConnection;
                    myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[GetRSCompanyConnectionString()].ToString());
                    myCommand = new SqlCommand(strSQL, myConnection);
                    SqlDataReader myDataReader;

                    param = new SqlParameter();
                    param.SqlDbType = SqlDbType.Int;
                    param.ParameterName = "@Estimateid";
                    param.Value = Estimateid;
                    myCommand.Parameters.Add(param);


                    param = new SqlParameter();
                    param.SqlDbType = SqlDbType.Int;
                    param.ParameterName = "@Companyid";
                    param.Value = companyid;
                    myCommand.Parameters.Add(param);

                    myConnection.Open();
                    myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
                    if (myDataReader.HasRows)
                    {
                        myDataReader.Read();

                        ddlWorkOrderType.SelectedIndex = 0;
                        ddlScheduleType.SelectedIndex = 0;
                        ddlEstimateStatus.SelectedIndex = 0;
                        btnViewEstimateReport.Visible = true;

                        if (myDataReader["ProjectId"] != DBNull.Value)
                        {
                            hfProjectId.Value = myDataReader["ProjectId"].ToString();
                        }
                        txtEstimateId.Text = myDataReader["EstimateId"].ToString();
                        txtWorkOrderName.Text = myDataReader["WorkOrderName"].ToString();

                        if (myDataReader["StartDT"] != DBNull.Value)
                        {
                            DateTime startdt = Convert.ToDateTime(myDataReader["StartDT"].ToString());
                            txtStartTime.Text = startdt.ToShortTimeString();
                            txtStartDate.Text = startdt.ToShortDateString();
                        }

                        if (myDataReader["EndDT"] != DBNull.Value)
                        {
                            DateTime enddt = Convert.ToDateTime(myDataReader["EndDT"].ToString());
                            txtEndTime.Text = enddt.ToShortTimeString();
                            txtEndDate.Text = enddt.ToShortDateString();
                        }

                        txtDescription.Text = myDataReader["Description"].ToString();
                        txtResponse.Text = myDataReader["Response"].ToString();

                        if (myDataReader["WorkOrderTypeID"] != DBNull.Value)
                            ddlWorkOrderType.SelectedValue = myDataReader["WorkOrderTypeID"].ToString();
                        if (myDataReader["AppointmentTypeID"] != DBNull.Value)
                            ddlScheduleType.SelectedValue = myDataReader["AppointmentTypeID"].ToString();
                        if (myDataReader["EstimateStatusId"] != DBNull.Value)
                            ddlEstimateStatus.SelectedValue = myDataReader["EstimateStatusId"].ToString();
                        txtLaborCost.Text = myDataReader["LaborCost"].ToString();
                        txtDiscountPercent.Text = myDataReader["DiscountPercent"].ToString();
                        txtDiscountAmount.Text = myDataReader["DiscountAmount"].ToString();
                        if (myDataReader["BillingContactId"] != DBNull.Value)
                            ddlBillingContactId.SelectedValue = myDataReader["BillingContactId"].ToString();
                        txtAdditionalInstruction.Text = myDataReader["AdditionalInstructions"].ToString();
                        txtPONumber.Text = myDataReader["PONumber"].ToString();
                        txtTerm.Text = myDataReader["Terms"].ToString();

                        if (ddlEstimateStatus.SelectedItem.Text.ToLower() == "accepted" || ddlEstimateStatus.SelectedItem.Text.ToLower() == "approved")
                        {
                            if (myDataReader["IsRolledIntoWorkOrder"] != DBNull.Value)
                            {
                                bool isRolledIntoWorkOrder = Convert.ToBoolean(myDataReader["IsRolledIntoWorkOrder"].ToString());
                                if (!isRolledIntoWorkOrder)
                                    btnRollEstimateIntoWorkOrder.Enabled = true;
                            }
                        }
                        SetControlEnabledState(false);
                        bHaveData = true;
                    }
                    myConnection.Close();
                }
                else
                {
                    btnEditEstimate.Visible = false;
                    btnSaveEstimate.Visible = true;
                    btnRemoveEstimate.Visible = false;
                    SetControlEnabledState(true);
                }
            }
            return bHaveData;
        }

        private void LoadBillingContactByLocationID(int companyid, int locationid)
        {
            SqlCommand myCommand;
            SqlDataReader myDataReader;
            String sqlSELECT = "select c.ContactId, cast(c.ContactId as varchar(5)) + ' - ' + c.FirstName + ' ' + c.lastname as ContactName, c.BillingLocationId from rs_tblContact c inner join rs_tblContactLocation cl on c.contactid=cl.contactid where cl.LocationId=@locationid and cl.CompanyId=@companyid";
            SqlParameter param;
            SqlConnection myConnection;

            myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings[GetRSCompanyConnectionString()].ToString());
            myCommand = new SqlCommand(sqlSELECT, myConnection);
            param = new SqlParameter();
            param.SqlDbType = SqlDbType.Int;
            param.ParameterName = "@companyid";
            param.Value = companyid;
            myCommand.Parameters.Add(param);

            param = new SqlParameter();
            param.SqlDbType = SqlDbType.Int;
            param.ParameterName = "@locationid";
            param.Value = locationid;
            myCommand.Parameters.Add(param);

            myConnection.Open();
            myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            ddlBillingContactId.Items.Clear();
            ddlBillingContactId.DataSource = myDataReader;
            ddlBillingContactId.DataTextField = "contactname";
            ddlBillingContactId.DataValueField = "contactid";
            ddlBillingContactId.DataBind();
            ddlBillingContactId.Items.Insert(0, new ListItem("< Please select >", "0"));
            myConnection.Close();
        }

        //protected void btnGenerateEstimate_Click(object sender, EventArgs e)
        //{
        //    RSUserIdentity userIdentity = GetRSUserIdentity();
        //    int CompanyId = userIdentity.RSCompanyId;
        //    int EstimateId = txtEstimateId.Text == "" ? 0 : Convert.ToInt32(txtEstimateId.Text);
        //    int LocationId = hfLocationId.Value == "" ? 0 : Convert.ToInt32(hfLocationId.Value);

        //    if (userIdentity.RSCanWrite)
        //    {
        //        int estimateid = PushEstimateToEstimate(CompanyId, EstimateId, userIdentity.RSCurrentUser);
        //        ucModalActionMessageControl.ShowModal("Estimate Generated Successfully!", "RSEstimateDetail.aspx?tabindex=5&locationid=" + LocationId + "&Estimateid=" + EstimateId, true);
        //    }
        //    else
        //        ucModalActionMessageControl.ShowModal("You Do Not Have Permission To Perform This Action!", "", false);
        //}

        //private int PushEstimateToEstimate(int CompanyId, int EstimateId, string CurrentUser)
        //{
        //    SqlCommand sqlCmd = new SqlCommand();

        //    SQLHelper.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
        //    SQLHelper.AddParamToSQLCmd(sqlCmd, "@EstimateId", SqlDbType.Int, 0, ParameterDirection.Input, EstimateId);
        //    SQLHelper.AddParamToSQLCmd(sqlCmd, "@CompanyId", SqlDbType.Int, 0, ParameterDirection.Input, CompanyId);
        //    SQLHelper.AddParamToSQLCmd(sqlCmd, "@CurrentUser", SqlDbType.NVarChar, 25, ParameterDirection.Input, CurrentUser);
        //    SQLHelper.SetCommandType(sqlCmd, CommandType.StoredProcedure, "rs_uspPushEstimateToEstimate");
        //    SQLHelper.ExecuteScalarCmd(sqlCmd);

        //    int returnValue = Convert.ToInt32(sqlCmd.Parameters["@ReturnValue"].Value);
        //    return returnValue;
        //}

        //protected void btnGenerateEstimate_Click(object sender, EventArgs e)
        //{
        //    RSUserIdentity userIdentity = GetRSUserIdentity();
        //    int CompanyId = userIdentity.RSCompanyId;
        //    int LocationId = hfLocationId.Value == "" ? 0 : Convert.ToInt32(hfLocationId.Value);
        //    int EstimateId = txtEstimateId.Text == "" ? 0 : Convert.ToInt32(txtEstimateId.Text);

        //    if (userIdentity.RSCanWrite)
        //    {
        //        UpdateEstimateStatus(CompanyId, LocationId, EstimateId);
        //        int estimateid = CreateNewEstimate(CompanyId, LocationId, EstimateId, userIdentity.RSCurrentUser);
        //        int locationId = hfLocationId.Value == "" ? 0 : Convert.ToInt32(hfLocationId.Value);
        //        int Estimateid = txtEstimateId.Text == "" ? 0 : Convert.ToInt32(txtEstimateId.Text);
        //        ucModalActionMessageControl.ShowModal("Estimate Generated Successfully!", "RSEstimateDetail.aspx?tabindex=5&locationid=" + locationId + "&Estimateid=" + Estimateid, true);
        //    }
        //    else
        //        ucModalActionMessageControl.ShowModal("You Do Not Have Permission To Perform This Action!", "", false);
        //}


        //private int CreateNewEstimate(int CompanyId, int LocationId, int EstimateId, string CurrentUser)
        //{
        //    SqlCommand sqlCmd = new SqlCommand();

        //    SQLHelper.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
        //    SQLHelper.AddParamToSQLCmd(sqlCmd, "@EstimateId", SqlDbType.Int, 0, ParameterDirection.Input, EstimateId);
        //    SQLHelper.AddParamToSQLCmd(sqlCmd, "@LocationId", SqlDbType.Int, 0, ParameterDirection.Input, LocationId);
        //    SQLHelper.AddParamToSQLCmd(sqlCmd, "@CompanyId", SqlDbType.Int, 0, ParameterDirection.Input, CompanyId);
        //    SQLHelper.AddParamToSQLCmd(sqlCmd, "@CurrentUser", SqlDbType.NVarChar, 25, ParameterDirection.Input, CurrentUser);
        //    SQLHelper.SetCommandType(sqlCmd, CommandType.StoredProcedure, "rs_uspSaveEstimate");
        //    SQLHelper.ExecuteScalarCmd(sqlCmd);

        //    int returnValue = Convert.ToInt32(sqlCmd.Parameters["@ReturnValue"].Value);
        //    return returnValue;
        //}

        protected void btnRollEstimateIntoWorkOrder_Click(Object sender, EventArgs e)
        {
            RSUserIdentity userIdentity = GetRSUserIdentity();
            int CompanyId = userIdentity.RSCompanyId;
            int EstimateId = txtEstimateId.Text == "" ? 0 : Convert.ToInt32(txtEstimateId.Text);
            int LocationId = hfLocationId.Value == "" ? 0 : Convert.ToInt32(hfLocationId.Value);

            SqlCommand sqlCmd = new SqlCommand();
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@EstimateId", SqlDbType.Int, 0, ParameterDirection.Input, EstimateId);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@CompanyId", SqlDbType.Int, 0, ParameterDirection.Input, CompanyId);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@CurrentUser", SqlDbType.NVarChar, 25, ParameterDirection.Input, userIdentity.RSCurrentUser);
            SQLHelper.SetCommandType(sqlCmd, CommandType.StoredProcedure, "rs_uspPushEstimateToWorkOrder");
            SQLHelper.ExecuteScalarCmd(sqlCmd);
            int WorkOrderid = Convert.ToInt32(sqlCmd.Parameters["@ReturnValue"].Value);
            if (WorkOrderid > 0)
                PushWorkOrderToScheduler(WorkOrderid, CompanyId, userIdentity.RSCurrentUser);

            ucModalActionMessageControl.ShowModal("Estimate Converted Into WorkOrder Successfully!", "RSLocationHistoryEstimates.aspx?locationid=" + LocationId, true);
        }
        private void PushWorkOrderToScheduler(int WorkOrderid, int companyid, string currentUser)
        {
            SqlCommand sqlCmd = new SqlCommand();
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@WorkOrderId", SqlDbType.Int, 0, ParameterDirection.Input, WorkOrderid);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@CompanyId", SqlDbType.Int, 0, ParameterDirection.Input, companyid);
            SQLHelper.AddParamToSQLCmd(sqlCmd, "@CurrentUser", SqlDbType.NVarChar, 25, ParameterDirection.Input, currentUser);
            SQLHelper.SetCommandType(sqlCmd, CommandType.StoredProcedure, "rs_uspPushWorkOrderToScheduler");
            SQLHelper.ExecuteScalarCmd(sqlCmd);
            int returnValue = Convert.ToInt32(sqlCmd.Parameters["@ReturnValue"].Value);
        }

    }
}